export default {
  props: {
    // value 格式
    site: {
      type: String
    },
  },
  data() {
    return {
      fileList: [],
      inited: false,
    }
  },
  watch: {
    value(val) {
      if (this.inited) return
      this.inited = true
      this.fileList = val.map(item => ({
        type: item.fileFormat, //类型
        size: item.fileSize,
        url: item.site
      }));
    },
  },
  methods: {
    fileChange() {
      try {
        let val = this.fileList && this.fileList.map(item => {
          if (!item.response) {
            return {
              fileFormat: item.type, //类型
              fileSize: item.size,
              site: item.url
            }
          }
          return {
            fileFormat: item.response.data.type, //类型
            fileSize: item.response.data.size,
            site: item.response.data.url
          }
        }) || [];
        this.$emit("input", val);
        this.$emit("update:site", val[0] && val[0].site || '');
        this.$emit('refresh')
      } catch (error) {
        console.log(error)
      }
    }
  },
  // mounted(){
  //   this.fileList = this.value.map(item => ({
  //     type: item.fileFormat, //类型
  //     size: item.fileSize,
  //     url: item.site
  //   }));
  // }
}